Skip to content

refactor: Centralise Postgres enum registration and fix petTrainer typo#316

Open
hhvrc wants to merge 1 commit into
developfrom
feature/pg-enum-refactor
Open

refactor: Centralise Postgres enum registration and fix petTrainer typo#316
hhvrc wants to merge 1 commit into
developfrom
feature/pg-enum-refactor

Conversation

@hhvrc

@hhvrc hhvrc commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@hhvrc hhvrc self-assigned this Jun 13, 2026
Copilot AI review requested due to automatic review settings June 13, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes Postgres enum mapping/registration for EF Core by introducing a [PgEnum] marker attribute and shared registration helpers, while also correcting the petTrainer enum label typo to petrainer via a migration.

Changes:

  • Added [PgEnum] + MapPgEnums()/RegisterPgEnums() to centralize Npgsql enum mapping and EF model enum registration.
  • Updated multiple enums to use explicit [PgName(...)] labels rather than relying on implicit enum member naming.
  • Added a migration to rename the Postgres enum value petTrainerpetrainer and updated snapshots accordingly.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Common/Utils/PgEnumAttribute.cs Adds a marker attribute to opt enums into centralized PG enum registration.
Common/OpenShockDb/UserNameBlacklist.cs Marks MatchTypeEnum as a PG enum and sets explicit PG labels.
Common/OpenShockDb/OpenShockContext.cs Replaces per-enum mapping/registration with centralized extension methods.
Common/OpenShockDb/NpgsqlEnumExtensions.cs Implements centralized mapping/registration of all PG enums.
Common/OpenShockDb/ConfigurationItem.cs Marks ConfigurationValueType as a PG enum and sets explicit PG labels.
Common/Models/ShockerModelType.cs Fixes PG label typo for PetTrainer (petTrainerpetrainer) and opts into centralized registration.
Common/Models/RoleType.cs Adds [PgEnum] and explicit PG labels.
Common/Models/PermissionType.cs Adds [PgEnum] to ensure it’s included in centralized registration.
Common/Models/PasswordHashingAlgorithm.cs Adds [PgEnum("password_encryption_type")] and explicit PG labels.
Common/Models/OtaUpdateStatus.cs Adds [PgEnum] and explicit PG labels.
Common/Models/ControlType.cs Adds [PgEnum] and explicit PG labels.
Common/Models/ControlLimitMode.cs Adds [PgEnum] and explicit PG labels.
Common/Migrations/OpenShockContextModelSnapshot.cs Updates model snapshot to reflect centralized enum definitions and renamed label.
Common/Migrations/20260612142230_RefactorPgEnums.Designer.cs Adds migration designer snapshot for the refactor migration.
Common/Migrations/20260612142230_RefactorPgEnums.cs Adds migration that renames the shocker_model_type value and updates enum annotations.
Files not reviewed (1)
  • Common/Migrations/20260612142230_RefactorPgEnums.Designer.cs: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +6
/// Marks an enum as a Postgres native enum type so it is automatically registered
/// with the EF Core model via <see cref="NpgsqlEnumExtensions.RegisterPgEnums"/>.
/// </summary>
Comment on lines +38 to +40
return new PgEnumInfo(
Map: b => b.MapEnum<TEnum>(pgTypeName),
Register: m => m.HasPostgresEnum(attr.Schema, pgTypeName, members));
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "password_encryption_type", new[] { "bcrypt_enhanced", "pbkdf2" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "permission_type", new[] { "shockers.use", "shockers.edit", "shockers.pause", "devices.edit", "devices.auth" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "role_type", new[] { "support", "staff", "admin", "system" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "shocker_model_type", new[] { "caiXianlin", "petTrainer", "petrainer998DR", "wellturnT330" });
Comment on lines 9 to 11
[PgName("caiXianlin")] CaiXianlin = 0,
[PgName("petTrainer")] PetTrainer = 1, // Misspelled, should be "petrainer",
[PgName("petrainer")] PetTrainer = 1,
[PgName("petrainer998DR")] Petrainer998DR = 2,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants